package com.sanjiahantang.youjiarole.module.match.views.impl;


import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.module.match.adapters.MatchAdapter;
import com.sanjiahantang.youjiarole.module.match.presenters.MatchPresenter;
import com.sanjiahantang.youjiarole.module.match.views.MatchView;
import com.sanjiahantang.youjiarole.umengshare.UmengShareManager;

/**
 * Created by zy on 2017/9/14.
 */

public class MatchActivity extends BaseMvpActivity<MatchView, MatchPresenter> implements MatchView, View.OnClickListener {


    private SwipeRefreshLayout refreshLayout;
    private RecyclerView recyclerView;
    private int id;
    private View titleLayout;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public MatchPresenter initPresenter() {
        return new MatchPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_match);
        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refreshLayout);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        titleLayout = findViewById(R.id.titleLayout);
        presenter.setMatchDetailListener(new MatchDetailListener() {

            @Override
            public void loadData(MatchAdapter matchDetailAdapter) {
                recyclerView.setAdapter(matchDetailAdapter);
                recyclerView.setLayoutManager(new LinearLayoutManager($this));
                refreshLayout.setRefreshing(false);
            }
        });

        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                presenter.loadMatchDetail($this, id);
            }
        });

        id = getIntent().getIntExtra(KEY_ID, 0);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("搭配详情");
        findViewById(R.id.fl_Left).setOnClickListener(this);
        View icon1 = findViewById(R.id.icon1);
        icon1.setVisibility(View.GONE);
        icon1.setOnClickListener(this);


        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (recyclerView.getChildAt(0) == null || recyclerView.getChildAt(0).findViewById(R.id.back) == null) {
                    return;
                }
                if (Utils.checkIsVisible($this, recyclerView.getChildAt(0).findViewById(R.id.back))) {
                    titleLayout.setVisibility(View.GONE);

                } else {
                    titleLayout.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    @Override
    public void initData() {
        presenter.loadMatchDetail($this, id);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_Left:
                finish();
                break;
            case R.id.icon1:
                UmengShareManager.share(this, "");
                break;
        }
    }

}
